package com.shijiwei.lifthelper.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shijiwei.lifthelper.R;
import com.shijiwei.lifthelper.bean.DBJoke;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2015/12/17.
 */
public class CollectJokeAdapter extends AppBaseAdapter {

    public CollectJokeAdapter(List<DBJoke> list, Context context) {
        super(list, context);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = inflater.inflate(R.layout.item_listview_collect_joke,parent,false);
            holder = new ViewHolder(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        DBJoke joke = (DBJoke) list.get(position);
        if (joke.getTitle().length()>0) {
            holder.titleText.setText(joke.getTitle());
        } else {
            holder.titleText.setVisibility(View.GONE );
        }
        holder.bodyText.setText(joke.getContent());
        return convertView;
    }


    private class ViewHolder extends BaseViewHolder{

        @ViewInject(R.id.tv_item_collect_title)
        private TextView titleText;
        @ViewInject(R.id.tv_item_collect_body)
        private TextView bodyText;

        public ViewHolder(View convertView) {
            super(convertView);
            x.view().inject(this,convertView);
        }
    }
}
